U.Json.like
语法格式:U.Json.like(arr, obj)
/**
* 根据条件,在obj数组中搜索符合条件的ojb2,obj2完全匹配,obj1部分匹配,模糊搜索。json添加一个like,与select最好有区别,完全匹配,部分匹配?
*
*
* @param {array} obj数组
* @param {object} key value的条件
* * @return {string} 排序的条件,json数组中的键名
*
* 例:
* [
0: {Name: "C语言项目", CreateDate: "2014-07-14T08:24:12.763Z", Type: "folder", ID: "e98d15ae-edce-6fcb-6778-a672ced906fd", IsDelete: false, …}
1: {Name: "测试", CreateDate: "2015-10-12T19:15:20.992Z", Type: "folder", ID: "c660310c-b003-f34a-b899-f2bfd9436e3a", IsDelete: true, …}
2: {Name: "C高级编程", CreateDate: "2015-10-13T19:44:09.848Z", Type: "folder", ID: "d26417da-eed7-01a4-0800-798655db7dc3", IsDelete: false, …}
3: {Name: "C中级编程", CreateDate: "2015-11-04T19:24:38.975Z", Type: "folder", ID: "f9e06a2e-bdb0-a137-a17a-6ee56cdf0535", IsDelete: false, …}
4: {Name: "test", CreateDate: "2020-10-20T00:18:39.299Z", Type: "folder", ID: "76b50ff0-cb49-6db2-0e90-56f9ed6a0f10", IsDelete: false, …}
5: {Name: "sdfasf", CreateDate: "2020-10-20T00:37:05.014Z", Type: "folder", ID: "99a8c0b2-08f8-4c4c-7206-b0ad11619460", IsDelete: false, …}
6: {Name: "test", CreateDate: "2020-10-20T00:37:10.005Z", Type: "folder", ID: "55b9ed70-d250-b595-c931-10bba27cdbd4", IsDelete: false, …}
]
此时需要判断 {Name:"test",IsDelete:false} 是否存在
*/
实例一
var a = [{ parentid: 1, username: "a" }, { parentid: 1, username: "b" }, { parentid: 2, username: "c" }]
var b = { parentid: 1 }
U.Json.select(a,b,2);
示例(可在编辑区域修改参数):
var obj1 = [{ parentid: 1, username: "a" }, { parentid: 1, username: "b" }, { parentid: 2, username: "c" }];
var obj2 = { username: "c" };
U.API.Json.AsynFun( U.Json.like(obj1,obj2));
运行结果展示区域: